<template>
  <div>
    <HomeHeader :user="user" name="小明"></HomeHeader>
    <HomeBody :user="user"></HomeBody>
  </div>

</template>     //html元素

<script>
//必要引入库
import Cookies from "js-cookie";
//组件
import HomeHeader from "@/components/home/framework/HomeHeader";
import HomeBody from "@/components/home/framework/HomeBody";
import request from "@/utils/request";

export default {
  name: "Home",
  data() {
    return{
      user:Cookies.get('user') ? JSON.parse(Cookies.get('user')) : null,
      name: '小明'
    }
  },        //存放数据的
  components:{
    HomeHeader,
    HomeBody
  },    //存放自定义组件的
  created() {
    console.log("页面正在创建");
    this.sayHello();
  },    //页面刚创建时但是数据还没有进行绑定的函数
  mounted() {
    console.log("数据已绑定")
    console.log("我的名字叫"+this.name)
  },    //绑定了数据后的函数
  methods:{
    sayHello(){
      console.log("hello world");
    },
    getUser(){
      request.get("/user/a/" + this.user.uname).then(res => {
        this.user.picture = res.data.picture
        this.user.socre=res.data.score;
        // console.log("picture:"+this.user.picture);
      })
    },
    quit(){
      //清除浏览器用户数据
      Cookies.remove('user')
      //返回登录界面
      window.location.href="/login";
    },
  },      //存放有哪些方法
  beforeMount() {
    if(this.user==null){
      this.quit();
    }
    this.getUser();
  }
}
</script>       //js

<style scoped>

</style>    //css
